package top.wilsonlv.jaguar.tenant;

import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.wilsonlv.jaguar.tenant.component.JaguarTenantLineHandler;
import top.wilsonlv.jaguar.tenant.component.TenantContextManagerInterceptor;

import javax.annotation.Resource;

/**
 * @author lvws
 * @since 2022/8/10
 */
@Configuration
public class JaguarTenantAutoConfiguration implements WebMvcConfigurer {

    @Resource
    private TenantContextManagerInterceptor tenantContextManagerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tenantContextManagerInterceptor).addPathPatterns("/**");
    }

    @Bean
    public TenantLineInnerInterceptor tenantLineInnerInterceptor(JaguarTenantLineHandler jaguarTenantLineHandler) {
        TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor();
        tenantLineInnerInterceptor.setTenantLineHandler(jaguarTenantLineHandler);
        return tenantLineInnerInterceptor;
    }

}
